package com.jms.framework.beans.context;

import com.jms.framework.beans.BeanDefinition;
import com.jms.framework.beans.factory.ObjectFactory;
import com.jms.framework.beans.utils.BeanInitializeUtils;

/**
 * JmsFrameworkBeanContext类是框架的核心部分，负责管理和初始化Bean
 * @author jms
 * @since 20250123
 * @version 1.0.0
 */
public class JmsFrameworkBeanContext extends AbstractBeanContext {
    private static volatile JmsFrameworkBeanContext beanContext;

    /**
     * 私有构造方法，不允许外部实例化
     */
    private JmsFrameworkBeanContext() {
    }

    public static JmsFrameworkBeanContext getInstance() {
        if (beanContext == null) {
            synchronized (JmsFrameworkBeanContext.class) {
                if (beanContext == null) {
                    beanContext = new JmsFrameworkBeanContext();
                }
            }
        }
        return beanContext;
    }

    @Override
    protected ObjectFactory<?> createSingletonBeanFactory(BeanDefinition beanDefinition) {
        return defaultCreateSingletonBeanFactory(beanDefinition);
    }

    @Override
    protected BeanDefinition createBeanDefinition(Class<?> clazz) {
        return BeanInitializeUtils.createBeanDefinition(clazz);
    }
}
